package com.结构型模式.装饰模式;

import javax.swing.*;
import java.awt.*;

/**
 * 莫莉卡
 * 抽象构件
 */
interface Morrigan{
    void display();
}

/**
 * 莫莉卡原生
 * 具体构件
 */
class Original extends JFrame implements Morrigan{
    private static final long serialVersionUID = 1L;
    private String t="Morrigan0.jpg";
    public Original()
    {
        super("《恶魔战士》中的莫莉卡·安斯兰");
    }
    public void setImage(String t)
    {
        this.t=t;
    }
    public void display()
    {

        this.setLayout(new FlowLayout());
        JLabel l1=new JLabel(new ImageIcon("src/img/"+t));
        this.add(l1);
        this.pack();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

    }

}

/**
 * 变形
 * 抽象装饰
 */
class Change implements Morrigan{

    Morrigan morrigan;
    Change(Morrigan morrigan){
        this.morrigan = morrigan;
    }
    @Override
    public void display() {
        morrigan.display();
    }
}

/**
 * 女妖
 * 具体构件
 */
class Succubus extends  Change{
    Succubus(Morrigan morrigan) {
        super(morrigan);
    }

    @Override
    public void display() {
        setChange();
        super.display();


    }
    void setChange(){
        System.out.println("变身成女妖");
        ((Original) super.morrigan).setImage("Morrigan1.jpg");

    }
}

/**
 * 少女
 * 具体构件
 */
class Gril extends Change{
    public Gril(Morrigan morrigan) {
        super(morrigan);
    }

    @Override
    public void display() {


        setChange();
        super.display();


    }
    void setChange(){
        System.out.println("变身美少女");
        ((Original) super.morrigan).setImage("Morrigan2.jpg");

    }
}
/**
 * 装饰模式
 */
public class Decorative {
    public static void main(String[] args) {
        Morrigan m = new Original();
        m.display();
        Morrigan m2 = new Gril(m);
        m2.display();
        Morrigan m3 = new Succubus(m);
        m3.display();

    }
}
